package org.mnswf.services {
	
	import com.dannypatterson.config.Settings;
	import com.dannypatterson.remoting.FaultEvent;
	import com.dannypatterson.remoting.ResultEvent;
	import com.dannypatterson.remoting.ServiceProxy;
	
	import flash.events.EventDispatcher;
	
	import mx.managers.CursorManager;
	
	import org.mnswf.model.Endorsement;
	
	public class ApproveEndorsementService extends EventDispatcher implements IService {
	
		private var service:ServiceProxy;
		private var endorsement:Endorsement;
		
		public function ApproveEndorsementService(endorsement:Endorsement) {
			this.endorsement = endorsement;
			service = new ServiceProxy(Settings.getInstance().remotingGateway, Settings.getInstance().memberService);
			service.addEventListener(ResultEvent.RESULT, onComplete, false, 0, true);
			service.addEventListener(FaultEvent.FAULT, onFault, false, 0, true);
		}
		
		private function onComplete(event:ResultEvent):void {
			CursorManager.removeBusyCursor();
			dispatchEvent(new ResultEvent(ResultEvent.RESULT, event.bubbles, event.cancelable, endorsement));
		}
		
		private function onFault(event:FaultEvent):void {
			CursorManager.removeBusyCursor();
			dispatchEvent(new FaultEvent(FaultEvent.FAULT, event.bubbles, event.cancelable, event.fault));
		}
		
		public function execute():void {
			service.approveEndorsement(endorsement.id);
		}
		
	}
}